

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>tomcat-web应用 - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-03-15 19:30" pubdate>
        2020年3月15日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.2k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      31
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">tomcat-web应用</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="Tomcat"><a href="#Tomcat" class="headerlink" title="Tomcat"></a>Tomcat</h2><ul>
<li><p>概述<br>   tomcat隶属于apache是开源的轻量级web应用服务，中小型企业普遍使用，是开发和调试jsp程序的首选。</p>
</li>
<li><p>Tomcat是什么<br>   简单的说，tomcat是一个中间件，在B/S架构中浏览器发出的http请求经过tomcat中间件，转发到最终的目的服务器上，响应消息再通过tomcat返回给浏览器。</p>
<p>   tomcat所做的事情主要就是，开启监听端口监听用户请求，解析用户发来的http请求然后访问到你指定的应用系统，返回的页面通过tomcat返回给用户（tomcat主要处理动态请求）。</p>
<ul>
<li>Apache,Nginx,Tomcat的区别<ul>
<li>Apache和Nginx用于处理静态资源，tomcat用来处理动态资源。</li>
<li>Apache和Nginx相比，Nginx更适合做前端服务器，适合负载均衡。</li>
<li>一般情况下，使用情况是Apache+Tomcat一起用或者，Nginx+Tomcat一起使用。</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="Tomcat的安装"><a href="#Tomcat的安装" class="headerlink" title="Tomcat的安装"></a>Tomcat的安装</h2><ul>
<li><p>环境准备</p>
<table>
<thead>
<tr>
<th>linux主机</th>
<th>ip:192.168.100.200</th>
</tr>
</thead>
<tbody><tr>
<td>jdk环境</td>
<td>tomcat安装包</td>
</tr>
</tbody></table>
</li>
<li><p>安装jdk-java环境</p>
<pre><code class="hljs routeros">[root@localhost ~]# tar -zxf jdk-8u201-linux-x64.tar.gz  # 解压
[root@localhost ~]# mv jdk1.8.0_201/ /usr/local/java 
[root@localhost ~]# echo <span class="hljs-string">&#x27;export JAVA_HOME=/usr/local/java # 变量java目录</span>
<span class="hljs-string">&gt; export JRE_HOME=/usr/local/java/jre # 变量java_jre目录</span>
<span class="hljs-string">&gt; export CALSSPATH=$JAVA_HOME/lib:$JRE_HOME/lib # 变量 java_lib目录</span>
<span class="hljs-string">&gt; export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin&#x27;</span> &gt;&gt; /etc<span class="hljs-built_in">/profile </span># 使java命令可以在命令端使用
[root@localhost ~]# rm -rf /usr/bin/java 删除系统原有的java命令
[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version 查看版本号
java version <span class="hljs-string">&quot;1.8.0_201&quot;</span>
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit<span class="hljs-built_in"> Server </span>VM (build 25.201-b09, mixed mode)</code></pre></li>
<li><p>安装Tomcat</p>
<pre><code class="hljs gradle">[root@localhost ~]# tar -zxf apache-tomcat-<span class="hljs-number">8.5</span>.<span class="hljs-number">35</span>.tar.gz 
[root@localhost ~]# mv apache-tomcat-<span class="hljs-number">8.5</span>.<span class="hljs-number">35</span> <span class="hljs-regexp">/usr/</span>local/tomcat
[root@localhost ~]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>bin/startup.sh        
 Using CATALINA_BASE:   <span class="hljs-regexp">/usr/</span>local/tomcat
 Using CATALINA_HOME:   <span class="hljs-regexp">/usr/</span>local/tomcat
 Using CATALINA_TMPDIR: <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>temp
 Using JRE_HOME:        <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/java/</span>jre
 Using <span class="hljs-keyword">CLASSPATH</span>:       <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>bin<span class="hljs-regexp">/bootstrap.jar:/u</span>sr<span class="hljs-regexp">/local/</span>tomcat<span class="hljs-regexp">/bin/</span>tomcat-juli.jar
 Tomcat started.
 [root@localhost ~]# netstat -anput |<span class="hljs-keyword">grep</span> <span class="hljs-number">8080</span>               
 tcp6       <span class="hljs-number">0</span>      <span class="hljs-number">0</span> :::<span class="hljs-number">8080</span>                 :::*                    LISTEN      <span class="hljs-number">20443</span>/java          
 [root@localhost ~]#</code></pre>
<p><img src="/images/tomcat/tomcatweb.png" srcset="/img/loading.gif"></p>
<ul>
<li>tomcat命令<pre><code class="hljs gradle">[root@localhost ~]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>bin/startup.sh  # 启动tomcat
[root@localhost ~]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>bin/shutdown.sh # 关闭tomcat
[root@localhost ~]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>logs/catalina.out # tomcat日志文件</code></pre>

</li>
</ul>
</li>
</ul>
<h2 id="Tomcat多实例"><a href="#Tomcat多实例" class="headerlink" title="Tomcat多实例"></a>Tomcat多实例</h2><blockquote>
<p>在一台主机部署多个tomcat<br>端口：8080 8081</p>
</blockquote>
<pre><code class="hljs crystal">[root@localhost ~]<span class="hljs-comment"># cp -r /usr/local/tomcat&#123;,1&#125;  # 复制一台 tomcat</span>
[root@localhost ~]<span class="hljs-comment"># ls /usr/local/</span>
bin  etc  games  <span class="hljs-keyword">include</span>  java  <span class="hljs-class"><span class="hljs-keyword">lib</span>  <span class="hljs-title">lib64</span>  <span class="hljs-title">libexec</span>  <span class="hljs-title">sbin</span>  <span class="hljs-title">share</span>  <span class="hljs-title">src</span>  <span class="hljs-title">tomcat</span>  <span class="hljs-title">tomcat1</span></span></code></pre>
<p>修改tomcat1</p>
<pre><code class="hljs lsl">[root@localhost ~]#  vim /usr/local/tomcat1/conf/server.xml  修改配置文件
&lt;Server port=<span class="hljs-string">&quot;8006&quot;</span> shutdown=<span class="hljs-string">&quot;SHUTDOWN&quot;</span>&gt; # <span class="hljs-number">8005</span> 改为 <span class="hljs-number">8006</span>
    &lt;Connector port=<span class="hljs-string">&quot;8081&quot;</span> protocol=<span class="hljs-string">&quot;HTTP/1.1&quot;</span> 
               connectionTimeout=<span class="hljs-string">&quot;20000&quot;</span>
               redirectPort=<span class="hljs-string">&quot;8444&quot;</span> /&gt; # <span class="hljs-number">8080</span> 改为 <span class="hljs-number">8081</span> <span class="hljs-number">8443</span> 改 <span class="hljs-number">8444</span>
 &lt;Connector port=<span class="hljs-string">&quot;8010&quot;</span> protocol=<span class="hljs-string">&quot;AJP/1.3&quot;</span> redirectPort=<span class="hljs-string">&quot;8444&quot;</span> /&gt; # <span class="hljs-number">8009</span> 改 <span class="hljs-number">8010</span> <span class="hljs-number">8443</span> 改 <span class="hljs-number">8444</span></code></pre>
<p>启动</p>
<pre><code class="hljs gradle">[root@localhost ~]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>bin/startup.sh # 启动tomcat
[root@localhost ~]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat1/</span>bin/startup.sh # 启动tomcat1</code></pre>
<p>访问 8080 和 8081端口<br><img src="/images/tomcat/8080.png" srcset="/img/loading.gif"><br><img src="/images/tomcat/8081.png" srcset="/img/loading.gif"></p>
<h2 id="Tomcat功能"><a href="#Tomcat功能" class="headerlink" title="Tomcat功能"></a>Tomcat功能</h2><ul>
<li><p>目录浏览</p>
<pre><code class="hljs gradle"> [root@localhost ~]# mkdir <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>webapps/hello
[root@localhost ~]# echo <span class="hljs-number">123</span> &gt; <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>webapps<span class="hljs-regexp">/hello/i</span>ndex.jsp
[root@localhost ~]# curl <span class="hljs-number">192.168</span>.<span class="hljs-number">100.200</span>:<span class="hljs-number">8080</span>/hello</code></pre>
<p><img src="/images/tomcat/123.png" srcset="/img/loading.gif"><br>开启目录浏览</p>
<pre><code class="hljs gherkin">[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># vim /usr/local/tomcat/conf/web.xml </span>
    <span class="hljs-variable">&lt;servlet&gt;</span>
        <span class="hljs-variable">&lt;servlet-name&gt;</span>default<span class="hljs-variable">&lt;/servlet-name&gt;</span>
        <span class="hljs-variable">&lt;servlet-class&gt;</span>org.apache.catalina.servlets.DefaultServlet<span class="hljs-variable">&lt;/servlet-class&gt;</span>
        <span class="hljs-variable">&lt;init-param&gt;</span>
            <span class="hljs-variable">&lt;param-name&gt;</span>debug<span class="hljs-variable">&lt;/param-name&gt;</span>
            <span class="hljs-variable">&lt;param-value&gt;</span>0<span class="hljs-variable">&lt;/param-value&gt;</span>
        <span class="hljs-variable">&lt;/init-param&gt;</span>
        <span class="hljs-variable">&lt;init-param&gt;</span>
            <span class="hljs-variable">&lt;param-name&gt;</span>listings<span class="hljs-variable">&lt;/param-name&gt;</span>
            <span class="hljs-variable">&lt;param-value&gt;</span>true<span class="hljs-variable">&lt;/param-value&gt;</span>         <span class="hljs-comment"># false改为true</span>
        <span class="hljs-variable">&lt;/init-param&gt;</span>
        <span class="hljs-variable">&lt;load-on-startup&gt;</span>1<span class="hljs-variable">&lt;/load-on-startup&gt;</span>
    <span class="hljs-variable">&lt;/servlet&gt;</span>
[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># /usr/local/tomcat/bin/shutdown.sh # 关闭tomcat</span>
[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># /usr/local/tomcat/bin/startup.sh  # 开启tomcat</span>
[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># mv /usr/local/tomcat/webapps/hello/index.jsp /usr/local/tomcat/webapps/hello/inde.jsp # 修改名字 修改index 因为 index 是默认网页名，会识别而不显示目录浏览</span>
[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># curl 192.168.100.200:8080/hello</span></code></pre>
<p><img src="/images/tomcat/inde.png" srcset="/img/loading.gif"></p>
</li>
<li><p>JVM内存监控</p>
<pre><code class="hljs awk">vim <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>webapps<span class="hljs-regexp">/hello/m</span>eminfo.jsp <span class="hljs-comment"># 创建一个jsp文件</span>
&lt;%
Runtime rtm = Runtime.getRuntime(); <span class="hljs-comment"># 获取变量rtm</span>
long mm = rtm.maxMemory()<span class="hljs-regexp">/1024/</span><span class="hljs-number">1024</span>; <span class="hljs-comment"># 最大内存</span>
long fm = rtm.freeMemory()<span class="hljs-regexp">/1024/</span><span class="hljs-number">1024</span>; <span class="hljs-comment"># 空闲内存</span>
long tm = rtm.totalMemory()<span class="hljs-regexp">/1024/</span><span class="hljs-number">1024</span>; <span class="hljs-comment">#总内存</span>

out.println(<span class="hljs-string">&quot;JVM memory detailed info:&lt;br&gt;&quot;</span>); <span class="hljs-comment"># 打印详细信息</span>
out.println(<span class="hljs-string">&quot;Max memory: &quot;</span>+mm+<span class="hljs-string">&quot;MB&quot;</span>+<span class="hljs-string">&quot;&lt;br&gt;&quot;</span>); <span class="hljs-comment"># 打印最大内存</span>
out.println(<span class="hljs-string">&quot;Free memory: &quot;</span>+fm+<span class="hljs-string">&quot;MB&quot;</span>+<span class="hljs-string">&quot;&lt;br&gt;&quot;</span>); <span class="hljs-comment"># 打印空闲内存</span>
out.println(<span class="hljs-string">&quot;Total memory: &quot;</span>+tm+<span class="hljs-string">&quot;MB&quot;</span>+<span class="hljs-string">&quot;&lt;br&gt;&quot;</span>); <span class="hljs-comment"># 打印总内存</span>
out.println(<span class="hljs-string">&quot;Available memory: &quot;</span>+(mm+fm-tm)+<span class="hljs-string">&quot;MB&quot;</span>+<span class="hljs-string">&quot;&lt;br&gt;&quot;</span>); <span class="hljs-comment"># 打印剩余可用内存</span>
%&gt;
wq <span class="hljs-comment"># 保存退出</span></code></pre>

<p><img src="/images/tomcat/jvm.png" srcset="/img/loading.gif"><br><img src="/images/tomcat/jvm2.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>839是jvm申请的内存，54是tomcat这个程序剩余的内存，107是tomcat向jvm申请的内存，786是jvm可用内存</p>
</blockquote>
<p>这里说一下，这里的最大内存不是系统的内存，而是jvm的内存，是jvm先从系统调取内存，然后分给tomcat来用，用的是堆内存的方法</p>
<blockquote>
<p>堆内存是jvm获取最大内存来给程序用<br>栈内存是程序用多少就像系统申请多少</p>
</blockquote>
</li>
</ul>
<h2 id="JVM远程调用（tomcat远程监控）"><a href="#JVM远程调用（tomcat远程监控）" class="headerlink" title="JVM远程调用（tomcat远程监控）"></a>JVM远程调用（tomcat远程监控）</h2><ul>
<li>需要新开一台主机 <table>
<thead>
<tr>
<th>linux主机</th>
<th>IP:192.168.100.201</th>
</tr>
</thead>
</table>
</li>
</ul>
<ul>
<li><p>修改tomcat配置文件</p>
  <pre><code class="hljs nix">[root@localhost ~]<span class="hljs-comment"># vim /usr/local/tomcat/bin/catalina.sh </span>
<span class="hljs-comment"># 在307行下添加</span>
<span class="hljs-attr">CATALINA_OPTS=&quot;-Djava.rmi.server.hostname=192.168.100.200</span> <span class="hljs-comment"># 远程调用监控的ip</span>
-Dcom.sun.management.jmxremote <span class="hljs-comment"># 使用jmx远程调用</span>
-Dcom.sun.management.jmxremote.<span class="hljs-attr">port=8080</span> <span class="hljs-comment"># 监控的端口</span>
-Dcom.sun.management.jmxremote.<span class="hljs-attr">ssl=false</span>  <span class="hljs-comment"># 不使用安全链接，因为没有ssh证书，所以这个就选false了</span>
-Dcom.sun.management.jmxremote.<span class="hljs-attr">authenticate=true&quot;</span> <span class="hljs-comment"># 监控时时都认证 (是否需要密码)</span>
[root@localhost ~]<span class="hljs-comment"># cd /usr/local/java/jre/lib/management/ # cd到远程调用的密码文件</span>
[root@localhost management]<span class="hljs-comment"># cp jmxremote.password.template jmxremote.password # cp一份 </span>
[root@localhost management]<span class="hljs-comment"># vim jmxremote.password #进入密</span>
码文件
 <span class="hljs-comment">#取消注释，这两个就是远程调用的角色，QED和R&amp;D用来占位，可以修改为你自己指定的密码</span>
monitorRole  QED  
controlRole   R&amp;D  
<span class="hljs-comment"># 修改为</span>
monitorRole  <span class="hljs-number">123456</span>
controlRole  <span class="hljs-number">123456</span>
[root@localhost management]<span class="hljs-comment"># chmod 600 /usr/local/java/jre/lib/management/jmxremote.* # 设置权限，给文件授权</span></code></pre>
<blockquote>
<p>开启新主机，新主机有jdk的环境</p>
  <pre><code class="hljs autoit"><span class="hljs-meta"># 新主机启动</span>
[root<span class="hljs-symbol">@localhost</span> ~]<span class="hljs-meta"># jconsole  # 开启监控 启动java监控和管理控制台</span></code></pre>
<p>  <img src="/images/tomcat/java%E7%9B%91%E6%8E%A7.png" srcset="/img/loading.gif"><br>图片上输入监控的主机和端口，密码是之前设置的</p>
</blockquote>
<p>  <img src="/images/tomcat/java%E7%9B%91%E6%8E%A72.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>出现这个是因为没有开启ssl，因为没有ssl证书，忽略就可以</p>
</blockquote>
<p>  <img src="/images/tomcat/Java%E7%9B%91%E6%8E%A73.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>这个就是监控页面</p>
</blockquote>
<h2 id="Tomcat后台管理"><a href="#Tomcat后台管理" class="headerlink" title="Tomcat后台管理"></a>Tomcat后台管理</h2></li>
<li><p>应用管理（app manager ）</p>
<pre><code class="hljs gradle">[root@localhost management]# vim <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>webapps<span class="hljs-regexp">/manager/M</span>ETA-INF/context.xml
&lt;Context antiResourceLocking=<span class="hljs-string">&quot;false&quot;</span> privileged=<span class="hljs-string">&quot;true&quot;</span> &gt;
  &lt;Valve className=<span class="hljs-string">&quot;org.apache.catalina.valves.RemoteAddrValve&quot;</span>
         allow=<span class="hljs-string">&quot;192.168.100.*&quot;</span> /&gt; # allow允许谁可以管理应用 改为自己网段的
[root@localhost management]# vim <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/tomcat/</span>conf/tomcat-users.xml     
&lt;role rolename=<span class="hljs-string">&quot;manager-gui&quot;</span>/&gt; role # 定义一个角色 rolename表示定义一个角色的名字
&lt;role rolename=<span class="hljs-string">&quot;manager-script&quot;</span>/&gt;
&lt;user username=<span class="hljs-string">&quot;manager&quot;</span> password=<span class="hljs-string">&quot;123.com&quot;</span> roles=<span class="hljs-string">&quot;manager-gui&quot;</span>/&gt; # 用户 使用的角色
&lt;user username=<span class="hljs-string">&quot;script&quot;</span> password=<span class="hljs-string">&quot;123.com&quot;</span> roles=<span class="hljs-string">&quot;manager-script&quot;</span>/&gt;
wq # 保存退出
重启tomcat
并访问 http:<span class="hljs-comment">//192.168.100.200:8080/manager/html</span></code></pre>
<blockquote>
<p> 用户角色解释<br>manager-gui 允许访问html接 路径：/manager/html<br>manager-script 允许访问纯文本接口 /manager/text<br>manager-jmxproxy 允许访问jmx代理接口 /manager/jmxproxy<br>manager-status 允许访问tomcat只读页面（状态页面 版本 JVM）/manager/status</p>
</blockquote>
<p><img src="/images/tomcat/tomcat%E5%BA%94%E7%94%A8%E7%AE%A1%E7%90%861.png" srcset="/img/loading.gif"><br><img src="/images/tomcat/tomcat%E5%BA%94%E7%94%A8%E7%AE%A1%E7%90%862.png" srcset="/img/loading.gif"><br><img src="/images/tomcat/tomcat%E5%BA%94%E7%94%A8%E7%AE%A1%E7%90%863.png" srcset="/img/loading.gif"><br>部署方式<br>   应用的部署方式</p>
<pre><code>通过应用管理来部署
手动部署
拖入war包（Web应用压缩包）</code></pre>
<p>  如果是自动部署，只需要将war包拖入webapps目录中，重启服务，即会自动部署，可以通过查看目录的内容的变化来验证</p>
<p>  而手动的方式，是为了不重启服务，在webapps目录中创建一个目录，作为web应用名，使用unzip将war包解压到该目录即可<br>  具体部署方式写一个独立的文章</p>
</li>
<li><p>主机管理 （虚拟主机host）</p>
<pre><code>[root@localhost ~]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml 
&lt;Context antiResourceLocking=&quot;false&quot; privileged=&quot;true&quot; &gt;
&lt;Valve className=&quot;org.apache.catalina.valves.RemoteAddrValve&quot;
      allow=&quot;^.*$&quot; /&gt; # 点表示任意一个字符，*代表前面字符的n次，代表全网段
[root@localhost ~]# vim /usr/local/tomcat/conf/tomcat-users.xml  
   # 倒数第二行添加
&lt;role rolename=&quot;admin-gui&quot;/&gt;
&lt;user username=&quot;admin&quot; password=&quot;123.com&quot; roles=&quot;admin-gui&quot;/&gt;
wq #保存退出
重启tomcat 
浏览页面  http://192.168.100.200:8080/host-manager/html</code></pre>
<p><img src="/images/tomcat/host-manager.png" srcset="/img/loading.gif"><br><img src="/images/tomcat/host-manager2.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>在图中的Host Name部分可以看到已有的虚拟主机<br>  Add Virtual Host 可以添加新的虚拟主机<br>  虚拟主机添加<br>  Name（域名）：<a target="_blank" rel="noopener" href="http://www.baidu.com/">www.baidu.com</a><br>  Aliases（别名）： baidu<br>  App Base：虚拟主机页面所在的web应用目录。如：/data，这个目录需要自己创建<br>  具体配置另写一个文章</p>
</blockquote>
<h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>manager和 hostmanager 另写一篇来配置<br>tomcat需要掌握的内容由，调优，配置等</p>
</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84/">微服务架构</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/tomcat/">tomcat</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/03/17/tomcat%E4%BC%98%E5%8C%96/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">tomcat优化</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/03/14/gitlab%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/">
                        <span class="hidden-mobile">gitlab远程仓库</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "tomcat-web应用&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
